<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'student.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$("#addStudent").click(function(){
				$("#add").css("display","block");
			});
			$("#proSelect").change(function(){
				$.ajax({
					type:"post",
					url:"./student/student!selectClasses.action",
					data:{tid:$("#termSelect").val(),pid:$("#proSelect").val(),n:Math.random()},
					dataType:"json",
					success:function(json){
						var classes=eval(json.jsonClass);
						var clas=document.getElementById("seleclass");
						clas.options.length=0;
						var op =new Option("--请选择--",-1);
						clas.options.add(op);
						for ( var i = 0; i < classes.length; i++) {
							var opt =new Option(classes[i].name,classes[i].id);
							clas.options.add(opt);
						}
					}					
				});
			});
			$("#proSelect1").change(function(){
				$.ajax({
					type:"post",
					url:"./student/student!selectClasses.action",
					data:{tid:$("#termSelect1").val(),pid:$("#proSelect1").val(),n:Math.random()},
					dataType:"json",
					success:function(json){
						var classes=eval(json.jsonClass);
						var clas=document.getElementById("seleclass1");
						clas.options.length=0;
						var op =new Option("--请选择--",-1);
						clas.options.add(op);
						for ( var i = 0; i < classes.length; i++) {
							var opt =new Option(classes[i].name,classes[i].id);
							clas.options.add(opt);
						}
					}					
				});
			});
			$("#dormSelect").change(function(){
				$.ajax({
					type:"post",
					url:"./student/selectBd!selectBd.action",
					data:{did:$(this).val(),n:Math.random()},
					dataType:"json",
					success:function(json){
						var classes=eval(json.jsonBd);
						var bdSelect=document.getElementById("bdSelect");
						bdSelect.options.length=0;
						var op =new Option("--请选择--",-1);
						bdSelect.options.add(op);
						for ( var i = 0; i < classes.length; i++) {
							var opt =new Option(classes[i].name,classes[i].id);
							bdSelect.options.add(opt);
						}
					}					
				});
			});
			$("#bdSelect").change(function(){
				$.ajax({
					type:"post",
					url:"./student/selectBr!selectBr.action",
					data:{bid:$(this).val(),n:Math.random()},
					dataType:"json",
					success:function(json){
						var classes=eval(json.jsonBr);
						var bdSelect=document.getElementById("beselect");
						bdSelect.options.length=0;
						var op =new Option("--请选择--",-1);
						bdSelect.options.add(op);
						for ( var i = 0; i < classes.length; i++) {
							var opt =new Option(classes[i].name,classes[i].id);
							bdSelect.options.add(opt);
						}
					}					
				});
			});
		});
	</script>
	<style type="text/css">
		#add{
			display: none;
		}
	</style>
  </head>
  
  <body>
    <div>
    	<s:form action="./student/student!show.action" theme="simple">
    	<table>
    		<tr>
    			<td>姓名:</td>
    			<td><s:textfield name="selectStudent.name" cssStyle="width:60px;"></s:textfield></td>
    			<td>性别:</td>
    			<td><s:select list="#{0:'男',1:'女' }" headerKey="-1" headerValue="--请选择--" name="selectStudent.gender" cssStyle="width:60px;"></s:select></td>
    			<td>年龄:</td>
    			<td><s:textfield name="selectStudent.age" cssStyle="width:60px;"></s:textfield></td>
    			<td>联系电话:</td>
    			<td><s:textfield name="selectStudent.phone" cssStyle="width:100px;"></s:textfield></td>
    			<td>住址:</td>
    			<td><s:textfield name="selectStudent.addr" cssStyle="width:100px;"></s:textfield></td>
    		</tr>
    		<tr>
  				<td>学期:</td>
  					<td><s:select list="#request.terms" name="selectStudent.classes.term.id" stu="1" headerKey="-1" headerValue="--请选择--" listKey="id" listValue="name" cssStyle="width:100px;" id="termSelect1"></s:select></td>
  					<td>专业:</td>
  					<td><s:select list="#request.professions" name="selectStudent.classes.profession.id" stu="1" headerKey="-1" headerValue="--请选择--" listKey="id" listValue="name" cssStyle="width:100px;" id="proSelect1"></s:select></td>
  					<td>班级:</td>
  					<td>
  					<select name="selectStudent.classes.id" id="seleclass1" style="width:100px;">
  						<option value="-1">--请选择--</option>
  					</select>
  					</td>
  				</tr>
    		<tr><td><s:submit value="查询"></s:submit></td></tr>
    	</table>
    	</s:form>
    </div>
  	<div>
  		<table border="1">
  				<tr>
  					<th>姓名</th>
  					<th>性别</th>
  					<th>年龄</th>
  					<th>联系电话</th>
  					<th>住址</th>
  					<th>学期</th>
  					<th>专业</th>
  					<th>班级</th>
  					<th>寝室</th>
  					<th>&nbsp;</th>
  				</tr>
  			<s:iterator value="students" var="student">
  				<tr>
  					<td>${student.name}</td>
  					<td><s:if test="#student.gender==0">男</s:if><s:else>女</s:else></td>
  					<td>${student.age}</td>
  					<td>${student.phone}</td>
  					<td>${student.addr}</td>
  					<td>${student.classes.term.name}</td>
  					<td>${student.classes.profession.name}</td>
  					<td>${student.classes.name}</td>
  					<td>${student.berth.bedroom.dorm.name}${student.berth.bedroom.name}&nbsp;${student.berth.name}号</td>
  					<td><a href="./student/student!deleteStudent.action?tid=${student.id}">删除</a></td>
  				</tr>
  			</s:iterator>
  			<tr><td colspan="9"><input type="button" id="addStudent" value="添加学生" /></td></tr>
  		</table>
  	</div>
  	<div id="add">
  		<s:form action="./student/student!addStudent.action" theme="simple">
  			<table>
  				<tr>
  				<td>姓名:</td>
  				<td><s:textfield name="student.name" cssStyle="width:100px;"></s:textfield></td>
  				<td>性别:</td>
  				<td><s:select list="#{0:'男',1:'女' }" value="0" name="student.gender" cssStyle="width:100px;"></s:select></td>
  				<td>年龄:</td>
  				<td><s:textfield name="student.age" cssStyle="width:100px;"></s:textfield></td>
  				<td>联系电话:</td>
  				<td><s:textfield name="student.phone"></s:textfield></td>
  				</tr>
  				<tr>
  					<td>学期:</td>
  					<td><s:select list="#request.terms" stu="0" headerKey="-1" headerValue="--请选择--" listKey="id" listValue="name" cssStyle="width:100px;" id="termSelect"></s:select></td>
  					<td>专业:</td>
  					<td><s:select list="#request.professions" headerKey="-1" headerValue="--请选择--" listKey="id" listValue="name" cssStyle="width:100px;" id="proSelect"></s:select></td>
  					<td>班级:</td>
  					<td>
  					<select name="student.classes.id" id="seleclass" style="width:100px;">
  						<option value="-1">--请选择--</option>
  					</select>
  					</td>
  					<td>住址:</td>
	  				<td><s:textfield name="student.addr"></s:textfield>
			    	</td>
  				</tr>
  				<tr>
  					<td>公寓:</td>
  					<td><s:select list="#request.dorms"  headerKey="-1" headerValue="--请选择--" listKey="id" listValue="name" cssStyle="width:100px;" id="dormSelect"></s:select></td>
  					<td>寝室:</td>
  					<td>
  					<select id="bdSelect"style="width:100px;">
  						<option value="-1">--请选择--</option>
  					</select>
  					</td>
  					<td>床号:</td>
  					<td>
  					<select name="student.berth.id" id="beselect" style="width:100px;">
  						<option value="-1">--请选择--</option>
  					</select>
  					</td>
  					<td><s:hidden name="student.berth.remark" value="1"></s:hidden></td>
  					<td><s:submit value="添加"></s:submit></td>
  				</tr>
  			</table>
  		</s:form>
  	</div>
  </body>
</html>
